package org.donald.lambda;

import java.util.Arrays;
import java.util.List;
import java.util.function.Predicate;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * @author donald 2018年3月7日 下午4:27:25
 */
public class BootStrapDemoBaseOldJavaVersion {
	private static final Logger log = LoggerFactory.getLogger(BootStrapDemoBaseOldJavaVersion.class);

	public static void main(String[] args) {
		// Java 8之前：
		new Thread(new Runnable() {
			@Override
			public void run() {
				log.info("Before Java8, too much code for too little to do");
			}
		}).start();
		// Java 8之前：
		List<String> features = Arrays.asList("Lambdas", "Default Method", "Stream API", "Date and Time API");
		for (String feature : features) {
			log.info(feature);
		}
		// 不使用lambda表达式为每个订单加上12%的税
		List<Integer> costBeforeTax = Arrays.asList(100, 200, 300, 400, 500);
		for (Integer cost : costBeforeTax) {
			double price = cost + .12 * cost;
			log.info(String.valueOf(price));
		}
		// 为每个订单加上12%的税
		// 老方法：
		List<Integer> costBeforeTax2 = Arrays.asList(100, 200, 300, 400, 500);
		double total = 0;
		for (Integer cost : costBeforeTax2) {
		    double price = cost + .12*cost;
		    total = total + price;
		}
		log.info("Total : " + total);
	}
}
